package com.ming.rabbitmq.one;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer {
    public static final String name="hello";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.137.66");
        factory.setVirtualHost("/");
        factory.setUsername("root");
        factory.setPassword("123456");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
//        声明函数
        DeliverCallback deliverCallback = (consumerTage,message)->{
            System.out.println("消息已收到");
            System.out.println(new String(message.getBody()));
        };
        CancelCallback cancelCallback = (consumerTag)->{
            System.out.println("消息已取消");
            System.out.println(consumerTag);
        };
//        消费者消费
//                          哪个队列 是否自动应答 接收消息回调 取消消息的回调
        channel.basicConsume(name,true,deliverCallback,cancelCallback);


    }
}
